package com.dreamwhale.machinery.goods.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.dreamwhale.machinery.config.DataResult;
import com.dreamwhale.machinery.goods.entity.YxStoreCart;
import com.dreamwhale.machinery.goods.service.YxStoreOrderService;
import com.dreamwhale.machinery.utils.WorkIdUtils;
import org.springframework.data.relational.core.sql.In;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author Author
 * @since 2020-05-28
 */
@RestController
@RequestMapping("/yxStoreOrder")
public class YxStoreOrderController {

    @Resource
    private YxStoreOrderService yxStoreOrderService;


    @RequestMapping("generateOrder")
    /**
     * @MethodName : generateOrder
     * @Description : 生成订单
     * @param : yxStoreCart
     * @param : payType
     * @param : addrId
     * @Author : DragonUncle
     * @Data : 14:30 2020/6/30
     * @return :
     */
    public ResponseEntity<DataResult> generateOrder(YxStoreCart yxStoreCart, Integer payType, Integer addrId) throws AlipayApiException {
        return ResponseEntity.ok(yxStoreOrderService.generateOrder(yxStoreCart, payType, addrId));
    }

    @RequestMapping("generateTrolleyOrder")
    /**
     * @MethodName : generateTrolleyOrder
     * @Description : 生成购物车订单
     * @param : trolleyId
     * @param : payType
     * @param : addrId
     * @Author : DragonUncle
     * @Data : 14:30 2020/6/30
     * @return :
     */
    public ResponseEntity<DataResult> generateTrolleyOrder(String trolleyId, Integer payType, Integer addrId) throws AlipayApiException {
        //  List<Integer> integers = JSON.parseArray(trolleyId, Integer.class);
        return ResponseEntity.ok(yxStoreOrderService.generateTrolleyOrder(trolleyId, payType, addrId));
    }

    public ResponseEntity<DataResult> orderPay() {
        return ResponseEntity.ok(null);
    }


    @RequestMapping("inquiryLogistics")
    /**
     * @MethodName : inquiryLogistics
     * @Description : 查询物流
     * @param : orderId
     * @Author : DragonUncle
     * @Data : 15:33 2020/7/9
     * @return :
     */
    public ResponseEntity<DataResult> inquiryLogistics(String orderId) {
        return ResponseEntity.ok(yxStoreOrderService.inquiryLogistics(orderId));
    }
}



